package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.entity.BaseCategory1;
import com.atguigu.gmall.product.entity.BaseCategory2;
import com.atguigu.gmall.product.entity.BaseCategory3;
import com.atguigu.gmall.product.service.BaseCategory1Service;
import com.atguigu.gmall.product.service.BaseCategory2Service;
import com.atguigu.gmall.product.service.BaseCategory3Service;
import com.atguigu.gmall.product.vo.SaveAttrInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("admin/product")
public class BaseCategoryController {

    @Autowired
    BaseCategory1Service baseCategory1Service;
    @Autowired
    BaseCategory2Service baseCategory2Service;
    @Autowired
    BaseCategory3Service baseCategory3Service;

    /*
    * 一级分类
    * */
    //admin/product/getCategory1
    @GetMapping("/getCategory1")
    public Result getCategory1() {

        List<BaseCategory1> list = baseCategory1Service.list();
        return Result.ok(list);
    }

//    获取一级分类下的二级分类
    @GetMapping("getCategory2/{c1Id}")
    public Result getCategory2(@PathVariable Long c1Id) {
//        List<BaseCategory2> list = baseCategory2Service.lambdaQuery()
//                .eq(BaseCategory2::getCategory1Id, c1Id)
//                .list();

        List<BaseCategory2> list = baseCategory2Service.lambdaQuery()
                .eq(BaseCategory2::getCategory1Id, c1Id)
                .list();
        return Result.ok(list);
    }

//    获取二级分类下的三级分类
    @GetMapping("/getCategory3/{c2Id}")
    public Result getCategory3(@PathVariable Long c2Id) {

        List<BaseCategory3> list = baseCategory3Service.lambdaQuery()
                .eq(BaseCategory3::getCategory2Id, c2Id)
                .list();
        return Result.ok(list);
    }


}
